﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace GSync
{

    public class InternalContact: InternalEntry
    {
        public InternalContact()
        {
            EMails = new List<string>(3);
            IMs = new List<string>(3);
            PhoneNumbers = new List<string>(3);
            Processed = false;
        }


        public List<string> EMails { get; private set; }

        public List<string> IMs { get; private set; }
        public List<string> PhoneNumbers { get; private set; }


        public string Name { get; set; }




        public override int GetHashCode()
        {
            long result = 0;

            result = (from email in EMails select (long)GetHash(email)).Sum();
            result += (from im in IMs select (long)GetHash(im)).Sum();
            result += (from phone in PhoneNumbers select (long)GetHash(phone)).Sum();
            result += GetHash(Name);

            result += GetHash(Notes);

            return Convert.ToInt32(result%int.MaxValue);
        }



        public override bool Equals(object obj)
        {
            return (obj != null) &&
                    (obj is InternalContact) &&
                    (GetHashCode() == obj.GetHashCode());
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(Name);
            sb.Append("E-mails: ");
            foreach(string s in EMails)
            {
                sb.AppendFormat("{0}  ",s);
            }

            sb.Append("\r\nIMs: ");
            foreach (string s in IMs)
            {
                sb.AppendFormat("{0}  ", s);
            }
            sb.Append("\r\nPhones: ");
            foreach (string s in PhoneNumbers)
            {
                sb.AppendFormat("{0}  ", s);
            }
            sb.AppendLine();
            sb.AppendLine( Notes);

            return sb.ToString();
        }
    }



    


}
